
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_last_message = binder_py('mx_eyelink_last_message')
eyelink_last_message.mx_c.headers = ['<eyelink.h>','"mex.h"']
eyelink_last_message.bindo += []
eyelink_last_message.mx_c.code = \
"""
INT16 _main( mxArray *oa[] )
{
    char FARTYPE *elb;
    INT16 code;

    code = eyelink_last_message(elb);
    
    if ( !code ){
	mwSize ts[] = {0};
	oa[0] = mxCreateCellArray(0,ts);
    } else {
	oa[0] = mxCreateString( elb );
	free(elb);
    }
    return code; 
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    char FARTYPE *elb;
    
    /* Verify input arguments. */
    if(nrhs > 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 2 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
            
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    if ( nlhs < 2 ){
	mxArray *t[1];
	*status = (double ) _main( t );
    } else if ( nlhs == 2 ){
	*status = (double ) _main( plhs+1 );
    } 

    return;   
}

"""

eyelink_last_message.mx_c.mdoc = \
"""function [ ] = mx_eyelink_last_message( )
%MX_EYELINK_LAST_MESSAGE Checks for and gets the last packet received, stores
% the data and the node address sent from.
%
% Returns:
% 0 if no message since last command sent, otherwise length of string.
% buf 	String buffer with return text message.
%
"""
eyelink_last_message.write_c()
eyelink_last_message.write_m()
eyelink_last_mesage.compile()
eyelink_last_message.write_sh()

